require('../liabs/swiper/swiper-bundle.css')


require('axios')
const axios = require('axios')

const Swiper = require('../liabs/swiper/swiper-bundle.js')

require('../css/commonCss/normalize.css')
require('../css/commonCss/basic.css')
require('../css/commonCss/property.css')
require('../css/commonCss/reset.css')
require('../liabs/iconfont/iconfont.css')



require('../css/home.less')
require('../css/commonCss/footer.less')

require('weui')
const weUi = require('weui.js')


//导入util
const util = require('../util/util')


console.log(Swiper)


document.addEventListener('DOMContentLoaded', function () {

  //封装swiper
  function setSwiper() {
    var mySwiper = new Swiper('.swiper', {
      loop: true, // 循环模式选项

      // 如果需要分页器
      pagination: {
        el: '.swiper-pagination',
      },
      autoplay: {
        disableOnInteraction: false,
      },
      // 如果需要滚动条
      scrollbar: {
        el: '.swiper-scrollbar',
      },
    })
  }

  setSwiper()


  /* 
    获取元素
  */
  const rank = document.querySelector('#rank')
  console.log(rank)
  const punchDay = document.querySelector('#punchDay')
  console.log(punchDay)
  const todayPunch = document.querySelector('#todayPunch')
  const badge = document.querySelector('#badge')
  const twoLeft = document.querySelector('.two-left')

  /* 
    首页数据渲染
  */

  axios.get('http://139.9.177.51:8099/headPageInfo', {
    params: {
      userId: localStorage.getItem('userId')
    }
  }).then(function (res) {
    if (res.data.status === 0) {

      rank.textContent = res.data.data.rank;
      punchDay.textContent = res.data.data.punchIn;
      badge.textContent = res.data.data.insigniaNum;

      res.data.data.isPunch === 'true' ? todayPunch.textContent = '已打卡' : todayPunch.textContent = '今日打卡'
    }
  })

  
  /* 
    今日打卡
  */

  todayPunch.addEventListener('click', function () {
    axios.get('http://139.9.177.51:8099/clockIn', {
      params: {
        userId: localStorage.getItem('userId')
      }
    }).then(function(res){
      console.log(res)
      if(res.data.status === 0){
        punchDay.textContent++;
        todayPunch.textContent = '已打卡'
        weUi.toast('打卡成功',1000)
      }else{
        weUi.toast('已打卡',1000)
      }
    })
  })

  //底部导航
  util.fixBottomNav('home')


  //运动数据的页面跳转
  twoLeft.addEventListener('click',function(){
    location.href = './motionData.html'
  })
})



